import 'package:flutter/material.dart';

void main() => {runApp(MyApp())};

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(title: '页面跳转返回数据', home: FirstPage());
  }
}

class FirstPage extends StatelessWidget {
  _navgateToXiaoJieJie(BuildContext context) async {
    // 返回的参数
    final resulte = await Navigator.of(context) .push(MaterialPageRoute(builder: (context) => new SecondScreen()));
    // 打印参数
    print(resulte["name"]);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("找小姐姐要电话"),
        ),
        body: Center(
          child: RaisedButton(
            child: Text('找小姐姐'),
            onPressed: () {
              _navgateToXiaoJieJie(context);
            },
          ),
        ));
  }
}

// 第二个页面
class SecondScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("第二个页面"),
        ),
        body: Center(
          child: RaisedButton(
            child: Text('返回'),
            onPressed: () {
              Navigator.pop(context, {"name": '小明'});
            },
          ),
        ));
  }
}
